import React from "react";
import {Link} from "react-router-dom"
import PageTitle from "../../../component/main_title/main_title"
import {BaseReq} from "../../../utils/baseReq"
import Upload from "../../../component/upload/upload"
import axios from "axios"
import $ from "jquery"
const baseReq=new BaseReq()
class AddProduct extends React.Component{
    constructor(props){
        super(props)
        
        // console.log("id",this.props.match.params.productId)
        // console.log("where",this.props.location.query.fromWhere)
        // console.log("where",this.props.location.query.productId)
    
        
        this.state={
          productShowList:["普通商品","轮播图片","热销商品","新品"],
          productStatusList:["上架","下架"],
          productOptionList:["夹克","卫衣","鞋子","短袖","长裤","背包","棉衣","羽绒服","风衣"],
          
          show:"普通商品",
          status:"上架",
          category:"夹克",
        }
    }
    componentDidMount(){
    //   if(this.state.productId){
    //     this.getProductDetail()
    //   }
    //   if(this.props.location){
    //     let that=this
    //     // console.log("where11",this.props.location.query.productId)
    //     this.getProductDetail()
    //   }
      
      
    }
    
    //获取下标
    getIndex(item,arr){
      return arr.indexOf(item)
    }
    //输入框变化时获取内容
    onInputChange(e){
      this.setState({
        [e.target.name]:e.target.value,
      })
    }
    onSelectChange(e){
      this.setState({
        [e.target.name]:e.target.value
      })
    }
    //选择图片
    onImageChange(e){
      this.setState({
        [e.target.name]:e.target.value
      })
    }
    //点击提交
    addProduct(){
      // let productShow=this.getIndex(this.state.show,this.state.productShowList)
      // let productStatus=this.getIndex(this.state.status,this.state.productStatusList)
      // let categoryType=this.getIndex(this.state.category,this.state.productOptionList)+1
      // "productName": "贝壳头",        "productPrice": 699,        "productStock": 110,        "productDescription": "三叶草",   
      let productStr={
        productPrice:this.state.price,
        productName:this.state.name,
        
        productStock:this.state.stock,
        productDescription:this.state.descript,
        productStatus:this.getIndex(this.state.status,this.state.productStatusList),
        productShow:this.getIndex(this.state.show,this.state.productShowList),
        categoryType:this.getIndex(this.state.category,this.state.productOptionList)+1, 
      }
      // let form2=document.getElementById("form1")
      // let formData = new FormData(form2)
    //   let userinfo=JSON.parse(window.localStorage.getItem("userInfo"))
    // formData.append("productStr",{"productName": "贝壳头55","productPrice": 699,"productStock": 110,"productDescription": "三叶草","productStatus": 0,"productShow": 1,"categoryType": 22})
    // formData.append("thumbnail","iVBORw0KGgoAAAANSUhEUgAAApoAAABvCAYAAABMzGB8AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABkVSURBVHhe7d37rxVX3cfx80c9Pzx/g1eUR3+oIU2FykVDoICVJpSL0IoIJrTc7zYIlJDQ0rSlLZdi0RAiBiXVxgpSyq1aKDdpQViPn+X5nixW15qZfc5eA+fM+5V8s/esy+wrsz97ZvZh4LPPPnN//etf3d///nf3z3/+0/3rX/9y//73vx0AALFTp065yZMnu6VLlzp9fgBAFYImAAAAihhQyCRoAgAAoN/YowkAAIAiCJoAAAAogqAJAACAIgiaAAAAKIKgCQAAgCIImgAAACiCoAkAAIAiCJoAAAAogqAJAACAIgiaAAAAKIKgCQAAgCIImgAAACiCoAkAAIAiCJoAAAAogqAJAACAIgiaAAAAKIKgCQAAgCIImgAAACiCoAkAAIAiCJoA0HGnT592O3fudNu3b+9U7dixwz92AOUQNAGg4xS4tO3vYumxAyinr0Hz2LFjbvbs2W78+PE91dSpU/1cAED7XnrpJXfz5s1Olh47gHL6GjSnTJmSDJJNSgEVANC+X/3qV+7GjRudLD12AOX0NWimAmQvBQBo37Zt29z169cra2BgoKd2lfXpMlXxeKuqvrBS45rOtdJjb2LcuHGD19Jy/VXzrE+XqUrJtaf0MjbUdF5q3HBvE2MXQbOQM2fOuOXLl7vbt28Ptozcvn37fPXTrVu33KpVq9ykSZPctGnT3MmTJwd7AHTF1q1bnT4L6kohLr4etsWVGp9bjquuX2Vjqm6nrvTYm2gSoMIxdr1qXmq8yc1Ltast126Xucqp6jM2JhzbZB665aEEzQkTJvhf+h08ePCB9rFktATNPXv2+HXev3/fv/7PPfec++STTwZ7AXTBli1b3NWrV3sqBbq4UmNSy6n2phXOqbvepPTYUxSY6qpKk/Fxmy2nxkrYrutWKbl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
    // formData.append("productImg0","iVBORw0KGgoAAAANSUhEUgAAApoAAABvCAYAAABMzGB8AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABkVSURBVHhe7d37rxVX3cfx80c9Pzx/g1eUR3+oIU2FykVDoICVJpSL0IoIJrTc7zYIlJDQ0rSlLZdi0RAiBiXVxgpSyq1aKDdpQViPn+X5nixW15qZfc5eA+fM+5V8s/esy+wrsz97ZvZh4LPPPnN//etf3d///nf3z3/+0/3rX/9y//73vx0AALFTp065yZMnu6VLlzp9fgBAFYImAAAAihhQyCRoAgAAoN/YowkAAIAiCJoAAAAogqAJAACAIgiaAAAAKIKgCQAAgCIImgAAACiCoAkAAIAiCJoAAAAogqAJAACAIgiaAAAAKIKgCQAAgCIImgAAACiCoAkAAIAiCJoAAAAogqAJAACAIgiaAAAAKIKgCQAAgCIImgAAACiCoAkAAIAiCJoA0HGnT592O3fudNu3b+9U7dixwz92AOUQNAGg4xS4tO3vYumxAyinr0Hz2LFjbvbs2W78+PE91dSpU/1cAED7XnrpJXfz5s1Olh47gHL6GjSnTJmSDJJNSgEVANC+X/3qV+7GjRudLD12AOX0NWimAmQvBQBo37Zt29z169cra2BgoKd2lfXpMlXxeKuqvrBS45rOtdJjb2LcuHGD19Jy/VXzrE+XqUrJtaf0MjbUdF5q3HBvE2MXQbOQM2fOuOXLl7vbt28Ptozcvn37fPXTrVu33KpVq9ykSZPctGnT3MmTJwd7AHTF1q1bnT4L6kohLr4etsWVGp9bjquuX2Vjqm6nrvTYm2gSoMIxdr1qXmq8yc1Ltast126Xucqp6jM2JhzbZB665aEEzQkTJvhf+h08ePCB9rFktATNPXv2+HXev3/fv/7PPfec++STTwZ7AXTBli1b3NWrV3sqBbq4UmNSy6n2phXOqbvepPTYUxSY6qpKk/Fxmy2nxkrYrutWKbl2k1tXXZkm1wFpPWhayBSFsbBvLBlp0NRroF9DakNo+h00tTdz6dKl7vz584Mtzr388svu6NG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yZuuthWyhubzrO5NrRXcWCpsKkBSujvZy5kKlqUy5ohgGwZNAMA204P74dtVnQ3LNnj9u+fbu7d++e7wvH5q4DQBULmpcuXaothbjUcqrdKtUW98VlfU3HVFU8L666oGnBKb5Miftyc7RsZcK2uM80bZOwPXU9N096HVNVQNFzNMOweejQoS/1x9WmOPxJVdDUr7q3bt3qD1urFOQUDocbNKsOnYchMQyaui/Wp0PrixcvHloO54XXAaCKguahtV9zFy5cqC0Ft6rrYVtqOdeWqrpxuf6m67c6tPbr2aAZBqXc9VDd+Hheaj2pNtPL+LBd18OytirD7a+bh+4p/mMghc3Nmzcn++Jqm/68kn64o5Co8yirguaVK1f8uZP6YY9+8KND2KtWrRpW0FRg1Y+R7MdAmqtzhSQOiWHQ1A+G5s6d6w+Z68dCGqcALOG8eB0AkGNB8/z587WlEBdexn1xezg+V+F4K2vP9avq5jatVNBUWIoDU2o5NyZul7rxuQrFy5Jqk7C9l3lifU3GxKrmoJuKB81eCgDQLgXNg2u+6s6dO1dZCnDhZZNKja2ar764P9Vm7XFbVXuuDq75WnaPZqguQDUJZ7HU2Kr5vYyvux+5dcXtqTZJtUmuHd1F0ASADrOg+dFHH2VL4S1ezlU8Jpxn7am2VHtY8Zjc+Lr1xNWPoBn3aTlXJl42qTaTmh9WKF42qfHxckpqTkrdetA9fQ2aOqSbCpBNatasWYNrAQC0RUHzwOqv+D+/1sU6sPqrjYImgOHpa9DUj1oUGFNBsqoUUO1vUAIA2mNBU+eQd7EImkBZfQ2aAIDRxQ6d628dd7GaHjoHMDwETQDosM/PH3Zntv+PD1zau9el0mPWY9dzAKAMgiYAdJyClvbqdbEImUBZBE0AAAAUQdAEAABAEQRNAAAAFDHmguZnn31GURQ1KqvfUrdBURTVZrFHEwAAAEUQNAEAAFAEQRMAAABFEDQBAABQgHP/DxXwGz9cZZbkAAAAAElFTkSuQmCC")
    
    // var request = new XMLHttpRequest();
    
    // request.open("POST", "/product/upload");
    // request.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
    // request.setRequestHeader("token","1534325821745303440_be2cdf39a9a84429b2ab7711a1dcd75f")
    // request.send(formData);


    let userinfo=JSON.parse(window.localStorage.getItem("userInfo"))
    var formData = new FormData()
    
    formData.append('thumbnail', this.state.mainImage);
    // formData.append('productImg0', $('#productImg0')[0].files[0]);
    let num=0
    for(let i=0;i<this.state.detailImageList.length;i++){
      
      formData.append('productImg'+num,this.state.detailImageList[i])
      num++
    }
    formData.append("productStr",JSON.stringify(productStr))
   
    
    //ajax请求
    // $.ajax({
    //             type: "post",
    //             url:  "/product/upload",
    //             data: formData,
    //             dataType: 'json',
    //             processData: false, // 告诉jQuery不要去处理发送的数据
    //             contentType: "application/x-www-form-urlencoded",// 告诉jQuery不要去设置Content-Type请求头
    //             beforeSend: function (XMLHttpRequest) {
    //                     XMLHttpRequest.setRequestHeader("token", userinfo);
    //                     },
    //             xhrFields:{withCredentials:true},
    //             async: true,    //默认是true：异步，false：同步。
    //             success: function (data) {
    //                 console.log(data)
    //             },
    //             error: function (data) {
    //               console.log(data)
    //             },
    //         });
   
    
    //   let thumbnail=this.state.mainImage[0].thumbUrl
    //   let productImg0=this.state.detailImage[0].thumbUrl
    //   let userinfo=JSON.parse(window.localStorage.getItem("userInfo"))
      let parmas={
        data: formData,
        type:"post",
        headers:{"Content-Type":"application/x-www-form-urlencoded",
                  "token":userinfo
      },
        url:"/product/upload"
      }
      baseReq._axios(parmas,res=>{
        console.log(res)
        if(res.data.success==true){
          alert("添加商品成功")
        }
      })
      
    }
    //通过id去加载商品信息
    getProductDetail(){
      console.log(this.state.productId)
      axios.get("/product/product_info/detail?product_id="+this.state.productId).then(res=>{
        this.setState({
    //       "productId": "1535901691115694782",
    // "productName": "CE1003 CE1005 CD6235",
    // "productPrice": 599,
    // "productStock": 95,
    // "productDescription": "Adidas三叶草代购 杨幂同款",
    // "productIcon": "/1535901691115694782/7038bd2d-1872-4fa1-83f6-fbf1b45d2090.jpg",
    // "productStatus": 0,
    // "productShow": 1,
    // "categoryType": 1,
          name:res.data.data.productName,
          price:res.data.data.productPrice,
          stock:res.data.data.productStock,
          descript:res.data.data.productDescription,
          show:this.state.productShowList[res.data.data.productShow],
          status:this.state.productStatusList[res.data.data.productStatus],
          category:this.state.productOptionList[res.data.data.categoryType-1],
          imageUrl:res.data.data.productIcon

        })
      },error=>{
        console.log(error)
      })

    }
    getMainImage(mainImage){
      
      
      this.setState({
        mainImage
      })
    }
    getDetailImage(detailImage){
      
      let detailImageList=[]
      detailImageList.push(detailImage)
      this.setState({
        detailImageList
      })
    }
    
    render(){
        return(
            
            <div id="page-wrapper">
                <PageTitle title="添加商品" />
                <div className="row">
                <form className="form-horizontal" id="form1">
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品名称</label>
                  <div className="col-sm-6">
                    <input   className="form-control" name="name" 
                    placeholder="商品名称" 
                            onChange={this.onInputChange.bind(this)}
                    />
                  </div>
                </div>
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品价格</label>
                  <div className="col-sm-6">
                  <div className="input-group">
                  <input  type="number" name="price" 
                           className="form-control"  placeholder="商品价格" 
                  onChange={(e)=>{this.onInputChange(e)}}/>
                  <span className="input-group-addon" id="basic-addon2">元</span>
                  </div>
                  </div>
                </div>
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品库存</label>
                  <div className="col-sm-6">
                  <div className="input-group">
                  <input  type="number" name="stock"
                   className="form-control"  placeholder="商品库存" 
                  onChange={(e)=>{this.onInputChange(e)}}/>
                  <span className="input-group-addon" id="basic-addon2">件</span>
                  </div>
                  </div>
                </div>
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品描述</label>
                  <div className="col-sm-6">
                    <input   className="form-control"
                     name="descript" placeholder="商品描述" 
                    onChange={(e)=>{this.onInputChange(e)}} />
                  </div>
                </div>
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品展示位置</label>
                  <div className="col-sm-6">
                    <select  name="show" className="form-control"
                     onChange={this.onSelectChange.bind(this)}>
                      {
                        this.state.productShowList.map((item,index)=>{
                       return (<option key={index} data-id={index} >{item}</option>) 
                      })}
                    </select>
                  </div>
                </div>
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品状态</label>
                  <div className="col-sm-6">
                    <select value={this.state.status} name="status" className="form-control" 
                     onChange={(e)=>{this.onSelectChange(e)}}>
                      {this.state.productStatusList.map((item,index)=>{
                        return <option key={index}>{item}</option>
                      })}
                    </select>
                  </div>
                </div>
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品所属分类</label>
                  <div className="col-sm-6">
                    <select  className="form-control" name="category"
                     onChange={(e)=>{this.onSelectChange(e)}}>
                      {this.state.productOptionList.map((item,index)=>{
                        return <option key={index}>{item}</option>
                      })}
                    </select>
                  </div>
                </div>
                <div className="form-group">
                  <label  className="col-sm-2 control-label">商品图片</label>
                  
                    <div className="col-sm-6">
                      
                      <div className="form-group">
                        <label >展示图片</label>
                        <Upload  getMainImage={this.getMainImage.bind(this)}/>
                    </div>
                    <div className="form-group">
                        <label >详细图片</label>
                        <Upload text="limit" getDetailImage={this.getDetailImage.bind(this)}/>
                    </div>
                    </div> 
                    
                    
                </div>
                
                <div className="form-group">
                  <div className="col-sm-offset-2 col-sm-10">
                    
                  <button type="button" className="btn btn-primary" onClick={this.addProduct.bind(this)} >添加</button>
                      
                    
                      
                      </div>
                </div>
              </form>
                </div>
                
            </div>
        )
    }
}
export default AddProduct